// See https://sequelize.org/master/manual/model-basics.html
// for more of what you can do here.
// 书刊信息表
import { Sequelize, DataTypes, Model } from 'sequelize';
import { Application } from '../declarations';
import { HookReturn } from 'sequelize/types/hooks';

export default function (app: Application): typeof Model {
  const sequelizeClient: Sequelize = app.get('sequelizeClient');
  const booksDeleteRecord = sequelizeClient.define('books-delete-record', {
    // ISBN编号
    isbn: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 所在分馆
    branchLibrary: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 馆藏地址
    bkAddress: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 装订工艺
    binding: {
      type: DataTypes.STRING,
      allowNull: true
    },
    // 书名
    bkName: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 其他名
    bkOtherName: {
      type: DataTypes.STRING,
      allowNull: true
    },
    // 作者
    author: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 出版时间
    publishTime: {
      type: DataTypes.STRING,
      allowNull: true
    },
    // 出版地
    publishAddress: {
      type: DataTypes.STRING,
      allowNull: true
    },
    // 出版社
    press: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 采购价
    purchasePrice: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    // 定价
    price: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    // 语言
    language: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 版次
    revision: {
      type: DataTypes.INTEGER,
      allowNull: true
    },
    // 印次
    impression: {
      type: DataTypes.INTEGER,
      allowNull: true
    },
    // 页数
    pages: {
      type: DataTypes.INTEGER,
      allowNull: true
    },
    // 简介
    abstract: {
      type: DataTypes.STRING,
      allowNull: true
    },
    // 备注
    remarks: {
      type: DataTypes.STRING,
      allowNull: true
    },
    // 类别
    classification: {
      type: DataTypes.STRING,
      allowNull: true
    },
    // 来源
    source: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 是否能离馆
    leave: {
      type: DataTypes.BOOLEAN,
      allowNull: false
    },
    // 状态：已借出/正常在馆
    state: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 操作人员
    operation: {
      type: DataTypes.STRING,
      allowNull: true
    },
    // 借阅人
    people: {
      type: DataTypes.STRING,
      allowNull: true
    },
  }, {
    hooks: {
      beforeCount(options: any): HookReturn {
        options.raw = true;
      }
    }
  });

  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  (booksinfo as any).associate = function (models: any): void {
    // Define associations here
    // See https://sequelize.org/master/manual/assocs.html
  };

  return booksinfo;
}
